﻿using System;


using System.Text;
using IAM.Interface.Model.Interface;
using System.Web;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 权限配置项
    /// </summary>
    public class CheckedItem : AbstractConvertObject,IConvertXml
    {
        #region 属性
        private string _acitemid = "";
        private bool _value =false;
        private string _attr1 = "";
        private string _attr2 = "";
        private string _attr3 = "";
        private string _attr4 = "";
        private string _attr5 = "";
        private string _attr6 = "";
        private string _attr7 = "";
        private string _attr8 = "";
        /// <summary>
        /// 权限配置项标识
        /// </summary>
        public string ACItemID
        {
            get
            {
                return _acitemid;
            }
            set
            {
                _acitemid = value;
            }
        }
        /// <summary>
        /// 目前均为“check”
        /// </summary>
        public bool Value
        {
            get
            {
                return _value;
            }
            set
            {
                _value = value;
            }
        }
        /// <summary>
        /// 扩展属性1
        /// </summary>
        public string Attr1
        {
            get
            {
                return _attr1;
            }
            set
            {
                _attr1 = value;
            }
        }
        /// <summary>
        /// 扩展属性2
        /// </summary>
        public string Attr2
        {
            get
            {
                return _attr2;
            }
            set
            {
                _attr2 = value;
            }

        }
        /// <summary>
        /// 扩展属性3
        /// </summary>
        public string Attr3
        {
            get
            {
                return _attr3;
            }
            set
            {
                _attr3 = value;
            }

        }
        /// <summary>
        /// 扩展属性4
        /// </summary>
        public string Attr4
        {
            get
            {
                return _attr4;
            }
            set
            {
                _attr4 = value;
            }

        }
        /// <summary>
        /// 扩展属性5
        /// </summary>
        public string Attr5
        {
            get
            {
                return _attr5;
            }
            set
            {
                _attr5 = value;
            }

        }
        /// <summary>
        /// 扩展属性6
        /// </summary>
        public string Attr6
        {
            get
            {
                return _attr6;
            }
            set
            {
                _attr6 = value;
            }

        }
        /// <summary>
        /// 扩展属性7
        /// </summary>
        public string Attr7
        {
            get
            {
                return _attr7;
            }
            set
            {
                _attr7 = value;
            }

        }
        /// <summary>
        /// 扩展属性8
        /// </summary>
        public string Attr8
        {
            get
            {
                return _attr8;
            }
            set
            {
                _attr8 = value;
            }

        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<CheckedItem");
                _xml.Append(" ACItemID=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.ACItemID )+ "\"");
                if (this.Value == true)
                {
                    _xml.Append(" Value=\"" + "check" + "\"");
                }
                else
                {
                    _xml.Append(" Value=\"" + "uncheck" + "\"");
                }

                try
                {
                    _xml.Append(" Attr1=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr1) + "\"");
                    _xml.Append(" Attr2=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr2) + "\"");

                    _xml.Append(" Attr3=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr3) + "\"");
                    _xml.Append(" Attr4=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr4) + "\"");
                    _xml.Append(" Attr5=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr5) + "\"");
                    _xml.Append(" Attr6=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr6) + "\"");
                    _xml.Append(" Attr7=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr7) + "\"");
                    _xml.Append(" Attr8=\"" + IAM.Interface.Common.EnDeCoding.Encode(this.Attr8) + "\"");
                }
                catch
                {
                    //_xml.Append(" Attr1=\"" + "" + "\"");
                    //_xml.Append(" Attr2=\"" + "" + "\"");
                    //_xml.Append(" Attr3=\"" + "" + "\"");
                    //_xml.Append(" Attr4=\"" + "" + "\"");
                    //_xml.Append(" Attr5=\"" + "" + "\"");
                    //_xml.Append(" Attr6=\"" + "" + "\"");
                    //_xml.Append(" Attr7=\"" + "" + "\"");
                    //_xml.Append(" Attr8=\"" + "" + "\"");
                }
                _xml.Append(" />");

                return _xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            //1.获取当前结点
            this.ACItemID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["ACItemID"].InnerText);
            if (this.CurrentXmlNode.Attributes["Value"].InnerText.ToLower() == "check")
            {
                this.Value = true;
            }
            else
            {
                this.Value = false;
            }
            //因为是后添加的属性，避免之前版本的的解析错误
            try
            {
                this.Attr1 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr1"].InnerText);
                this.Attr2 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr2"].InnerText);
                this.Attr3 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr3"].InnerText);
                this.Attr4 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr4"].InnerText);
                this.Attr5 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr5"].InnerText);
                this.Attr6 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr6"].InnerText);
                this.Attr7 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr7"].InnerText);
                this.Attr8 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.Attributes["Attr8"].InnerText);
            }
            catch
            {
                //this.Attr1 = "";
                //this.Attr2 = "";
                //this.Attr3 = "";
                //this.Attr4 = "";
                //this.Attr5 = "";
                //this.Attr6 = "";
                //this.Attr7 = "";
                //this.Attr8 = "";
            }
            return this;
        }
        #endregion
        #region 重写Equals
        /// <summary>
        /// 确定指定的 CheckedItem 对象是否等效于当前 CheckedItem
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            CheckedItem ci = null;
            try
            {
                ci = (CheckedItem)obj;
            }
            catch
            {
                return false;
            }
            bool result = true;
            if (this.ACItemID != ci.ACItemID)
            {
                result = false;
            }
            else if (this.Value != ci.Value)
            {
                result = false;
            }
            else if (this.Attr1 != ci.Attr1)
            {
                result = false;
            }
            else if (this.Attr2 != ci.Attr2)
            {
                result = false;
            }
            else if (this.Attr3 != ci.Attr3)
            {
                result = false;
            }
            else if (this.Attr4 != ci.Attr4)
            {
                result = false;
            }
            else if (this.Attr5 != ci.Attr5)
            {
                result = false;
            }
            else if (this.Attr6 != ci.Attr6)
            {
                result = false;
            }
            else if (this.Attr7 != ci.Attr7)
            {
                result = false;
            }
            else if (this.Attr8 != ci.Attr8)
            {
                result = false;
            }
            return result;

        }

        #endregion
        #region 重写GetHashCode
        /// <summary>
        /// 哈希函数
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return _acitemid.GetHashCode() * _value.GetHashCode();
        }
        #endregion
    }
}
